package cn.scau.server.controller;


import cn.scau.server.dto.EmpDeptDTO;
import cn.scau.server.dto.PositionPageDTO;
import cn.scau.server.pojo.Position;
import cn.scau.server.service.PositionService;
import cn.scau.server.vo.EmpDeptQueryVO;
import cn.scau.server.vo.EmpPosDeptVO;
import cn.scau.server.vo.ResultVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 代码不跑我先跑
 * @since 2025-03-30
 */
@RestController
@RequestMapping("/position")
public class PositionController {
    @Autowired
    private PositionService positionService;

    //添加职位
    @PostMapping("/addPosition")
    public ResultVO addPosition(String positionName, String deptName) {
        return positionService.addPosition(positionName, deptName);
    }

    //修改职位
    @PostMapping("/editPosition")
    public ResultVO editPosition(Integer positionId, String positionName) {
        return positionService.editPosition(positionId, positionName);
    }

    //删除职位
    @PostMapping("/deletePosition")
    public ResultVO deletePosition(Integer positionId) {
        return positionService.deletePosition(positionId);
    }

    //分页查询职位信息
    @GetMapping("/pagePosition")
    @ApiOperation("分页查询职位信息")
    public ResultVO<IPage<Position>> pagePosition(PositionPageDTO positionPageDTO) throws Exception {
        return positionService.pagePosition(positionPageDTO);
    }

    //根据职位编号查找所有拥有该职位的员工信息
    @GetMapping("/getEmpsByPositionId")
    public ResultVO getEmpsByPositionId(Integer positionId) {
        return positionService.getEmpsByPositionId(positionId);
    }

    //查询所有职位
    @GetMapping("/getAllPositions")
    public ResultVO<List<Position>> getAllPositions() {
        List<Position> positions = positionService.list();
        return ResultVO.success("查询成功",positions);
    }

    //根据部门名称查找所有职位
    @GetMapping("/getPositionsByDeptName")
    public ResultVO<List<String>> getPositionsByDeptName(String deptName){
        return positionService.getPositionsByDeptName(deptName);
    }
}
